<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>你好饿哇</div>
    <button class="btn1">复制</button>
    <button class="btn2">粘贴</button>
    <br>
    <input type="text" style="position:absolute;opacity: 0;" class='input1'>

    <br>
    <textarea type="text" class='input2'></textarea>


    <span></span>
    <script>
        const btn = document.querySelector('.btn1'),
            btn2 = document.querySelector('.btn2'),
            oDiv = document.querySelector('div'),
            oInput = document.querySelector('.input1'),
            oText = document.querySelector('.input2'),
            oSpan = document.querySelector('span');
        btn.onclick = function() {
            copy(oDiv.innerHTML)
        }




        function copy(value, callback) {
            // #ifdef H5
            var oInput = document.createElement('input'); //创建一个隐藏input（重要！）
            oInput.value = value; //赋值
            document.body.appendChild(oInput);
            oInput.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令         
            // oInput.style.display = 'none';
            document.body.removeChild(oInput)
            typeof callback == 'function' && callback();
        }
    </script>

</body>

</html>